#include "queue.h"
#include <stdlib.h>
#include <string.h>

//创建队列
queue* Create()
{
	queue* s;
	s =(queue*)malloc(sizeof(queue));
	if(s == NULL)
	{
		perror("maollc s");
		return NULL;
	}
	memset(s, 0, sizeof(s->data));
	s->front = 0;
	s->rear = 0;
	return s;
}


//清空队列
int Clear(queue* s)
{
	if(s == NULL)
	{
		printf("s_NULL\n");
		return -1;
	}
	s->front = s->rear = 0;
	return 0;
}


//判断是否为空
int Empty(queue* s)
{
	if(s == NULL)
	{
		printf("s_NULL\n");
		return -1;
	}
	return (s->front == s->rear ? 0 : 1);
}


//是否为满
int Full(queue* s)
{
	if(s == NULL)
	{
		printf("s_NULL\n");
		return -1;
	}
	//0就是满了，1没有满
	if((s->rear + 1) % N == s->front)
	{
		return 0;
	}
	else
	{
		return 1;
	}

}


//入队
int insert(queue* s, int value)
{
	if(s == NULL)
	{
		printf("s_NULL\n");
		return -1;
	}
	if(Empty(queue* s))
	{
		printf("满了\n");
		return -1;
	}
	//更新位置和内容
	s->data[s->rear] = value;
	s->rear = (s->rear + 1) % N;
}


//出队
int dele(queue* s)
{
	int ret;
	if(s == NULL)
	{
		printf("s_NULL\n");
		return -1;
	}
	if( Empty(queue* s))
	{
		printf("队为空\n");
		return -1;
	}
	s->front =(s->front + 1) % N;
	ret = s->data[s->front];
	return ret;

}


//释放
queue* s_free(queue* s)
{
	if(s == NULL)
	{
		printf("s_NULL");
		return NULL;
	}
	free(s);
	return NULL;
}














